package com.lagou.search.controller;

import com.lagou.search.api.Result;
import com.lagou.search.dto.EsOrderQueryDTO;
import com.lagou.search.entity.Order;
import com.lagou.search.entity.es.EsOrder;
import com.lagou.search.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * 订单控制器
 * @author yzh
 * @since 2021/12/2
 **/
@Api(tags = "订单模块")
@Validated
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @ApiOperation(value = "订单列表")
    @GetMapping("/list")
    public Result<List<EsOrder>> list(EsOrderQueryDTO esOrderQuery) {
        return Result.data(orderService.list(esOrderQuery));
    }

    /**
     * 订单保存
     * @param order 订单
     */
    @ApiOperation(value = "订单保存")
    @PostMapping("/save")
    public void save(@Valid @RequestBody Order order) {
        orderService.save(order);
    }

    /**
     * 订单删除
     * @param id 订单ID
     */
    @ApiOperation(value = "订单删除")
    @PostMapping("/remove")
    public void remove(@ApiParam(required = true, value = "订单ID") Long id) {
        orderService.remove(id);
    }

    /**
     * 订单同步到Es
     */
    @ApiOperation(value = "订单同步到Es")
    @PostMapping("/syncToEs")
    public void syncToEs() {
        orderService.syncToEs();
    }

}